<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>uncaught_exceptions</title>
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Chapter 1. Boost.Core">
<link rel="up" href="../index.html" title="Chapter 1. Boost.Core">
<link rel="prev" href="type_name.html" title="type_name">
<link rel="next" href="use_default.html" title="use_default">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
<td align="center"><a href="../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="type_name.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="use_default.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="core.uncaught_exceptions"></a><a class="link" href="uncaught_exceptions.html" title="uncaught_exceptions">uncaught_exceptions</a>
</h2></div></div></div>
<div class="toc"><dl class="toc"><dt><span class="section"><a href="uncaught_exceptions.html#core.uncaught_exceptions.header_boost_core_uncaught_excep">Header
      &lt;boost/core/uncaught_exceptions.hpp&gt;</a></span></dt></dl></div>
<div class="simplesect">
<div class="titlepage"><div><div><h3 class="title">
<a name="idm14724"></a>Authors</h3></div></div></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
          Andrey Semashev
        </li></ul></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="core.uncaught_exceptions.header_boost_core_uncaught_excep"></a><a class="link" href="uncaught_exceptions.html#core.uncaught_exceptions.header_boost_core_uncaught_excep" title="Header &lt;boost/core/uncaught_exceptions.hpp&gt;">Header
      &lt;boost/core/uncaught_exceptions.hpp&gt;</a>
</h3></div></div></div>
<p>
        The header <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">core</span><span class="special">/</span><span class="identifier">uncaught_exceptions</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
        defines the <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">core</span><span class="special">::</span><span class="identifier">uncaught_exceptions</span></code> function, which is
        a more portable implementation of the same named function introduced in C++17.
        The function returns the number of the currently pending exceptions. When
        that function returns a value greater than 0, throwing an exception from
        a destructor can terminate the program.
      </p>
<p>
        Unfortunately, the function cannot be implemented on every pre-C++17 compiler,
        although the most commonly used compilers are supported. When the compiler
        does not provide the necessary functionality, <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">core</span><span class="special">::</span><span class="identifier">uncaught_exceptions</span></code>
        returns a non-zero value if at least one exception is pending (i.e. not necessarily
        the number of pending exceptions), and <code class="computeroutput"><span class="identifier">BOOST_CORE_UNCAUGHT_EXCEPTIONS_EMULATED</span></code>
        macro is defined.
      </p>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.uncaught_exceptions.header_boost_core_uncaught_excep.example"></a><a class="link" href="uncaught_exceptions.html#core.uncaught_exceptions.header_boost_core_uncaught_excep.example" title="Example">Example</a>
</h4></div></div></div>
<pre class="programlisting"><span class="keyword">class</span> <span class="identifier">my_class</span>
<span class="special">{</span>
<span class="keyword">private</span><span class="special">:</span>
    <span class="keyword">const</span> <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">m_exception_count</span><span class="special">;</span>

<span class="keyword">public</span><span class="special">:</span>
    <span class="identifier">my_class</span><span class="special">()</span> <span class="special">:</span> <span class="identifier">m_exception_count</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">core</span><span class="special">::</span><span class="identifier">uncaught_exceptions</span><span class="special">())</span>
    <span class="special">{</span>
    <span class="special">}</span>

    <span class="special">~</span><span class="identifier">my_class</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">(</span><span class="keyword">false</span><span class="special">)</span>
    <span class="special">{</span>
        <span class="keyword">if</span> <span class="special">(</span><span class="identifier">m_exception_count</span> <span class="special">==</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">core</span><span class="special">::</span><span class="identifier">uncaught_exceptions</span><span class="special">())</span>
            <span class="identifier">do_something_potentially_throwing</span><span class="special">();</span>
    <span class="special">}</span>
<span class="special">};</span>
</pre>
</div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2014 Peter Dimov<br>Copyright © 2014 Glen Fernandes<br>Copyright © 2014 Andrey Semashev<p>
        Distributed under the <a href="http://boost.org/LICENSE_1_0.txt" target="_top">Boost
        Software License, Version 1.0</a>.
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="type_name.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="use_default.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
